package ms07.ticket;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;

public class DebugLog {
	private static DebugLog instance;
	public static DebugLog getInstance(){
		if(instance==null){
			instance = new DebugLog();
		}
		
		return instance;
	}
	
	protected Context last_context;
	protected boolean active = false;
	
	public DebugLog(){
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MyApplication.getInstance());
		
		this.active = prefs.getBoolean("debugging", false);
	}
	
	public void setContext(Context context){
		this.last_context = context;
	}
	
	public void log(String message, Context context){
		this.last_context = context;
		this.log(message);
	}
	
	public void log(String message){
		if(!this.active) return;
		
		Log.d(MyApplication.APP_NAME, message);
		//System.out.println(message);
		//Toast toast = Toast.makeText(this.last_context, message, Toast.LENGTH_LONG);
		//toast.show();
	}
	
	public void log(String message, Exception e){
		if(!this.active) return;
		
		Log.d(MyApplication.APP_NAME, message, e);
	}

	public void error(String message) {
		if(!this.active) return;
		
		Log.e(MyApplication.APP_NAME, message);
	}

	public void error(String message, Exception e) {
		if(!this.active) return;
		
		Log.e(MyApplication.APP_NAME, message, e);
	}
}
